package com.fairytask.ui
{
	import com.fairytask.engine.GameStage;
	import com.fairytask.engine.define.ResConfig;
	import com.greensock.TweenLite;
	import com.greensock.easing.Cubic;
	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	
	/**
	 * 通缉榜获取积分效果，从任务UI移动到积分UI然后消失
	 * @author pangj
	 * 
	 */
	public class WantedScoreEffect extends Sprite
	{
		private var mc:Bitmap;           //图片
		private var pointArr:Array=[];   //坐标数据
		private var func:Function;
		
		
		/**
		 * @param arr        [起点x，起点y,终点x,终点y]
		 * @param onComplete 完成后的事件
		 * 
		 */
		public function WantedScoreEffect(arr:Array,onComplete:Function=null)
		{
			var res:String = ResConfig.pngTaskPath + "Task_Trade.png";
			pointArr=arr;
			//QueueLoader.StartLoad(res,onLoad);
			func = onComplete;
		}
		
		private function onLoad(val:Bitmap):void
		{
			mc = val;
			mc.smoothing = true;
			mc.x = pointArr[0];
			mc.y = pointArr[1];
			addChild(mc);
			onStartPoint();
		}
		
		/**
		 *开始播放效果 
		 * 
		 */
		private function onStartPoint():void
		{
			TweenLite.to(mc, 0.8, {onComplete:playAnime});
		}
		private function playAnime():void
		{
			TweenLite.to(mc, 2.7, {x:pointArr[2], y:pointArr[3], ease:Cubic.easeOut,onComplete:onEndPoint});
		}
		private function onEndPoint():void
		{
			TweenLite.to(mc, 0.2, {onComplete:onClear});
		}
		
		/**
		 * 消失后清除 
		 * 
		 */
		private function onClear():void
		{
			if(null != func)
			{
				func();
			}
			if(null != this.parent)
			{
				this.parent.removeChild(this);
			}
		}
		public function show():void
		{
			GameStage.uiSpace.addTop(this);
		}
	}
}